package org.payeco.risk.dao;

import java.util.Collection;
import java.util.List;

import org.payeco.risk.entity.PayecoRiskRule;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface PayecoRiskRuleRepository extends JpaRepository<PayecoRiskRule, Long>{

	public PayecoRiskRule findByRiskNo(@Param("riskno")String riskno);

	public List<PayecoRiskRule> findByState(@Param("state") String state);

	public List<PayecoRiskRule> findByStateAndSysmerchantno(@Param("state")String state, @Param("sysmerchantno")String sysmerchantno );

	@Query(" select p from PayecoRiskRule p where p.state = 'State.Enabled' order by p.priority ")
	public List<PayecoRiskRule> findAllEnableRules();

	@Query(" select p from PayecoRiskRule p where p.sysmerchantno in ?1 and p.checkmode = ?2 and p.state = ?3 order by p.priority ")
	public List<PayecoRiskRule> findRiskruleListWithGeneric(Collection<String> merchantGroups, String checkmode, String state);
	//
	@Query(" select p from PayecoRiskRule p where p.sysmerchantno in ?1 and p.checkmode = ?2 and p.state = ?3 and p.riskaction like ?4% order by p.priority ")
	public List<PayecoRiskRule> findRiskruleListWithGenericAndAction(Collection<String> merchantGroups, String checkmode, String state, String riskaction);
	//
	@Query(" select p from PayecoRiskRule p where p.sysmerchantno in ?1 and p.checkmode = ?2 and p.state = ?3 and (p.riskaction in ?4 or p.riskaction not in ?5) order by p.priority ")
	public List<PayecoRiskRule> findRiskruleListWithAtionType(Collection<String> merchantGroups, String checkmode, String state, Collection<String> inActions, Collection<String> noAtions);

}
